package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 控制器
 *
 * @author DiXiaoNie
 * @date 2022/12/21
 * @since 2022/12/21 16:30
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    /**
     * wm材料服务
     */
    @Resource
    private WmMaterialService wmMaterialService;

    /**
     * 上传图片
     *
     * @param file 文件
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/21
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadImage(@RequestParam("multipartFile") MultipartFile file) {

        return this.wmMaterialService.uploadImage(file);
    }

    /**
     * 查找列表
     *
     * @param dto dto
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/21
     */
    @PostMapping("/list")
    public ResponseResult findList(@RequestBody WmMaterialDto dto) {

        return this.wmMaterialService.findList(dto);
    }

    /**
     * 删除图片
     *
     * @param id 图片ID
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/21
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult deleteImage(@PathVariable Integer id) {
        return this.wmMaterialService.deleteImage(id);
    }


    /**
     * 收藏
     *
     * @param id id 图片Id
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/21
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id) {
       return this.wmMaterialService.collect(id);
    }


    /**
     * 取消收藏
     *
     * @param id id
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2022/12/21
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult unCollect(@PathVariable Integer id) {

        return this.wmMaterialService.unCollect(id);

    }
}
